package leetcode.code0875;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

public class Solution implements IDebug {

	public int minEatingSpeed(int[] piles, int h) {
		int max = 10000;
		int ans = 1;
		int min = 1;
		while (min <= max) {
			int mid = ((max - min) >> 1) + min;
			int cur = this.eat(piles, mid);
			if (cur <= h) {
				ans = mid;
				max = mid - 1;
			} else {
				min = mid + 1;
			}
		}
		return ans;
	}

	private int eat(int[] piles, int mid) {
		int ans = 0;
		for (int pile : piles) {
			ans += (pile + mid - 1) / mid;
		}
		return ans;
	}

	@Override
	public void debug1() {
		HelpDebug.compare(1, this.minEatingSpeed(HelpDebug.str2array3("[30,11,23,4,20]"), 100));
	}

	@Override
	public void debug2() {
		HelpDebug.compare(5, this.minEatingSpeed(HelpDebug.str2array3("[30,11,23,4,20]"), 20));
	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug2();
		so.debug1();
		so.debug3();
		so.debug4();

	}

}
